import requests
import time

from seleniumwire import webdriver # pip install selenium-wire

# 应用账号（请替换为真实账号）
app_key = 'app_key'
# 应用密码（请替换为真实密码）
app_secret = 'app_secret'

api_url = "https://api.xiaoxiangdaili.com/ip/get"

def getProxy():
    res = requests.get(api_url, params={'appKey': app_key, 'appSecret': app_secret, 'wt': 'text', 'cnt': 1})
    content = str(res.content,'utf-8')
    print("API response: " + content)
    return content

proxy = getProxy()

options = {
    'proxy': {
        'http': "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": app_key, "pwd": app_secret, "proxy": proxy},
        'https': "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": app_key, "pwd": app_secret, "proxy": proxy}
    }
}

driver = webdriver.Firefox(seleniumwire_options=options,executable_path="#geckodriver驱动存放路径#")

driver.get('http://httpbin.org/ip')

# 获取页面内容
print(driver.page_source)

# 延迟3秒后关闭当前窗口，如果是最后一个窗口则退出
time.sleep(3)
driver.close()